package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.RemoteProductSkuService;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.SkuQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class RemoteProductSkuFallbackFactory implements FallbackFactory<RemoteProductSkuService>
{
    @Override
    public RemoteProductSkuService create(Throwable cause) {
        log.error("商品服务调用失败:{}", cause.getMessage());
        return new RemoteProductSkuService() {
            @Override
            public R<List<ProductSku>> getTopSale(String source) {
                return R.fail("获取商品sku失败" + cause.getMessage());
            }

            @Override
            public TableDataInfo getProductSkuList(Integer pageNum, Integer pageSize, String source, SkuQuery skuQuery) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setCode(R.FAIL);
                tableDataInfo.setMsg("获取商品sku失败" + cause.getMessage());
                return tableDataInfo;
            }
        };
    }
}
